﻿@using Projectmanagement.Entity
@using Projectmanagement.Utl
@model IQueryable<IGrouping<string, Task>>
@if (Model != null)
{
    
    foreach (var p in Model)
    {
        string statusImage = "";
        int? milestoneID = 0;
    <div class="arrowBox">
        <div class="pointBox">
            <div class="point" style="height: 23px;">
                <img src="/images/arrowPoint.gif" style="display: block;" /></div>
            <div style="color: #28a900; font-size: 17px;">@p.Key</div>
        </div>
        @foreach (var t in p.OrderBy(t => t.Milestone.EndDate).ThenBy(t => t.Milestone.ID).ThenBy(t => t.EndDate))
        {
            if (t.MilestoneID != milestoneID && milestoneID != 0 && CH.DB.Milestone.Where(s => s.ID == milestoneID).Any())
            {
                var name = CH.GetAllDatas<Milestone>().Where(s => s.ID == milestoneID).First().MilestoneName;
            <div class="lcb">
                <span>
                  @name
                </span>
            </div>
            }
            milestoneID = t.MilestoneID;
            var now = DateTime.Now;
            if (t.StartDate > now)
            {
                if (t.TaskState.Code == 100)
                {
                    statusImage = "greenPoint.gif";
                }
                else
                {
                    statusImage = "whitePoint.gif";
                }
            }
            else
                if (t.StartDate < now && t.EndDate >= now)
                {
                    if (t.TaskState.Code == 100)
                    {
                        statusImage = "greenPoint.gif";
                    }
                    else
                    {
                        statusImage = "bluePoint.gif";
                    }
                }
                else if (t.EndDate < now)
                {
                    if (t.TaskState.Code == 100)
                    {
                        statusImage = "greenPoint.gif";
                    }
                    else
                    {
                        statusImage = "redPoint.gif";
                    }
                }
            if (t.TaskState.Code == 90) { statusImage = "yellowPoint.gif"; }
            if (t.TaskState.Code == -10 || t.TaskState.Code == -1) { statusImage = "greyPoint.gif"; }
            if (statusImage == "") { statusImage = "whitePoint.gif"; }
            <div class="pointBox">
                <div class="point">
                    <a href="javascript:void(0);">
                        <img src="/images/@statusImage" style=" display: block; border:0"/></a></div>
                <div class="task" title="@t.Name">
                    <a href="javascript:void(0);" onclick="showtask(@t.ID)" class="v_Task">@t.Name</a></div>
            </div>
        }
        @if (milestoneID != 0 && CH.DB.Milestone.Where(s => s.ID == milestoneID).Any())
        {
            <div class="lcb">
                <span>
                    @CH.DB.Milestone.Where(s => s.ID == milestoneID).First().MilestoneName
                </span>
            </div>
        }
        <div class="arrow">
            <img src="/images/arrow.gif" style="display: block;" /></div>
    </div>
    }
}
